home *** CD-ROM | disk | FTP | other *** search
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* */
- /* MADE - Macintosh Application Development Essentials */
- /* --------------------------------------------------- */
- /* (c) Sig Software, http://www.sigsoftware.com/ */
- /* */
- /* These files can only be used for experimental purposes. To obtain */
- /* fully commented code, source code for the functions in Essential */
- /* Extras.h and permission for usage in final projects, you must */
- /* purchase a license. See documentation for more information. */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* */
- /* Essential Extras.h */
- /* ------------------ */
- /* */
- /* Headers for extra utility functions which you will receive when */
- /* you purchase a license for MADE. Included in unregistered */
- /* version so you know what you're missing! */
- /* */
- /* Version 1.2.0 - 20th November 1998 */
- /* Version 1.4.0 - 26th May 1999 - Added threading, navigation */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- #include "User Extra Settings.h"
-
- /*
- Essential Dialogs.c
-
- These functions are shortcuts for common operations you need to perform on
- modal or modeless dialog boxes.
- */
-
- /*
- For use with any dialog items
- */
-
- Handle GetItemHandle(DialogPtr dialog, short item);
- void GetItemRect(DialogPtr dialog, short item, Rect* rect);
- void SetItemHandle(DialogPtr dialog, short item, Handle handle);
- void InvalItem(DialogPtr dialog, short item);
- // invalidates an item, causing it to be redrawn in next event loop
- /*
- For use with check boxes, radio buttons, push buttons and other controls
- */
-
- short GetItemValue(DialogPtr dialog, short item);
- void SetItemValue(DialogPtr dialog, short item, short value);
- Boolean ToggleItem(DialogPtr dialog, short item);
- // toggles an item (on<->off) and returns its new value
- void SetItemEnabled(DialogPtr dialog, short item, Boolean enabled);
- // uses HiliteControl(..., 255);
-
- /*
- For use with static text and edit text items
- */
-
- void GetItemText(DialogPtr dialog, short item, Str255 string);
- long GetItemNumber(DialogPtr dialog, short item);
- void SetItemText(DialogPtr dialog, short item, Str255 string);
- void SetItemNumber(DialogPtr dialog, short item, long number);
-
- /*
- Essential Strings.c
-
- These optimised functions perform many manipulations on MacOS Str255 structures.
- Where there is a pair ...String and ...Chars, use the ...String version when dealing
- with two Str255s, and the ...Chars version when dealing with one Str255 and one
- string specified by a pointer and length. Read the variable names carefully to
- determine which order to pass in the parameters!
- */
-
- /*
- Copying strings
- */
-
- void CloneString(Str255 source, Str255 result);
- void CloneChars(unsigned char* sourcePtr, unsigned char sourceLen, Str255 result);
-
- /*
- Adding and removing from strings
-
- A position of zero specifies the beginning of the string.
- */
-
- void AppendString(Str255 original, Str255 append);
- void AppendChars(Str255 original, unsigned char* appendPtr, unsigned char appendLen);
- void InsertString(Str255 insert, Str255 original, unsigned char position);
- void InsertChars(unsigned char* insertPtr, unsigned char insertLen,
- Str255 original, unsigned char position);
- void RemoveFromString(Str255 original, unsigned char position, unsigned char count);
-
- /*
- Searching and comparing strings
-
- The string tables which are used when searching case INsensitively are for Roman
- scripts only. Use the MacOS international functions if you want to be script-
- independent, but these will be quicker otherwise.
-
- A position of zero returned by a Find function means the string was not found. A
- position of one means it was found at the start, two for the second characters, etc...
-
- The Relative functions return a value of -1, 0, 1 for first-second, i.e. :
- -1 => the first string is alphabetically before the second
- 0 => the first string is alphabetically identical to the second
- 1 => the first string is alphabetically after the second
- */
-
- unsigned char FindInString(Str255 find, Str255 within, Boolean caseSensitive);
- unsigned char FindChars(unsigned char* findPtr, unsigned char findLen,
- unsigned char* inPtr, unsigned char inLen, Boolean caseSensitive);
- short RelativeString(Str255 first, Str255 second, Boolean caseSensitive);
- short RelativeChars(unsigned char* firstPtr, unsigned char firstLen,
- unsigned char* secondPtr, unsigned char secondLen,
- Boolean caseSensitive);
-
- /*
- Essential Buffers.c
-
- These functions let you deal with buffers, for access to files and memory. Their major
- benefit is that they do things in lumps so that your code runs quickly, and is not bogged
- down too much by the vagaries of Apple's memory and file manager.
- */
-
- #define memoryBufferBlockSize 1024
- #define saveBufferBlockSize 1024
- #define loadBufferBlockSize 1024
- // set these to the size you want. Bigger means slightly faster but
- // uses more memory. 1024 (i.e. 1K) should be perfectly adequate.
-
- /*
- Memory Buffer - automatically growing block of memory
-
- Open with CreateMemoryBuffer, then write as much as you want using WriteMemoryBuffer,
- checking for returned errors as you go. When you're finished, call CloseMemoryBuffer.
- The handle it returns will be unlocked and is now owned by you. You must dispose of
- it yourself using DestroyHandle once you're finished with it.
- */
-
- typedef struct MemoryBuffer {
- Handle handle;
- long allocated, used;
- } MemoryBuffer;
-
- Error CreateMemoryBuffer(MemoryBuffer* buffer);
- Error WriteMemoryBuffer(MemoryBuffer* buffer, void* dataPtr, long count);
- Handle CloseMemoryBuffer(MemoryBuffer* buffer);
-
- /*
- Save Buffer - buffered access for writing a file
-
- Open with OpenSaveBuffer, then write as much as you want using WriteSaveBuffer,
- checking for returned errors as you go. When you're finished, call CloseSaveBuffer.
- OpenSaveBuffer will delete any previously existing file with the specified
- location, so be warned. If you used the Standard File dialogs to select the file,
- the user will already have been asked about replacing the previous file.
- */
-
- typedef struct SaveBuffer {
- char data[saveBufferBlockSize];
- short fileRefNum;
- long used;
- } SaveBuffer;
-
- Error OpenSaveBuffer(SaveBuffer* buffer, FSSpec* fileSpec, OSType creator, OSType type);
- Error WriteSaveBuffer(SaveBuffer* buffer, void* dataPtr, long count);
- Error CloseSaveBuffer(SaveBuffer* buffer);
-
- /*
- Load Buffer - buffered access for reading a file
-
- Open with OpenLoadBuffer, then read using ReadLoadBuffer or ReadLoadBufferUntil,
- checking for returned errors as you go. LoadBufferRemaining will tell you how
- much of the file remains for reading. When you're finished, call CloseLoadBuffer.
- */
-
- typedef struct LoadBuffer {
- char data[loadBufferBlockSize];
- short fileRefNum;
- long read, valid;
- } LoadBuffer;
-
- Error OpenLoadBuffer(LoadBuffer* buffer, FSSpec* fileSpec);
- Error ReadLoadBuffer(LoadBuffer* buffer, void* dataPtr, long count);
- Error ReadLoadBufferUntil(LoadBuffer* buffer, char untilChar,
- char* dataPtr, long* count);
- // untilChar will be matched exactly. The data returned will include
- // this character. On entry, the variable pointed to be count must
- // contain the maximum number of characters to read. On exit, it will
- // tell you the actual number of characters read. You can check
- // whether you had enough space to find the last character by looking
- // at the last character, i.e. dataPtr[*count-1].
- Error LoadBufferRemaining(LoadBuffer* buffer, long* remaining);
- void CloseLoadBuffer(LoadBuffer* buffer);
-
- /*
- Essential URLs.c
-
- These functions let you open a URL in the user's browser, using Internet Config
- first (if Use_Internet_Config is set to 1), then trying Netscape then Internet
- Explorer. The other functions are used along the way, and are put here because
- you might want to put them to other purposes.
- */
-
- Error OpenURL(Str255 url);
- Error FindApplication(OSType creator, ProcessSerialNumber *process);
- // High-level function. This tries FindApplicationProcess first,
- // then FindApplicationFile and OpenApplicationFile.
- Error FindApplicationProcess(OSType creator, ProcessSerialNumber *process);
- // Looks for the process currently running
- Error FindApplicationFile(OSType creator, FSSpec* fileSpec);
- // Looks for the process in desktop files of all mounted volumes
- Error OpenApplicationFile(FSSpec* fileSpec, ProcessSerialNumber *process);
- // Launches application
- Error SendGetURLEvent(ProcessSerialNumber *process, Str255 url);
- // Sends the standard GURL event to the specified process
-
- /*
- Essential Threads.c
-
- These functions implement a simple, non-preemptive, non-prioritizing threading
- architecture which doesn't require Apple's Threads Manager.
- */
-
- typedef enum { threadInit, threadWork, threadPaused, threadResumed, threadKill } ThreadMessage;
- // Commands sent to your thread procedure
- // On threadInit, do whatever is necessary to start off but don't start working
- // On threadWork, do your thread's actual work - make it as little as possible
- // On threadPaused, you have just gone from being unpaused to paused
- // On threadResumed, you have just gone from being paused to bring unpaused
- // On threadKill, clear up any extra data you allocated. You will received threadKill
- // either if your thread was killed from outside or if you returned threadDone below
-
- typedef enum { threadOK, threadError, threadPause, threadDone } ThreadResult;
- // Your thread procedure must return one of these after every call
- // Return threadOK if things are OK but there's still more work to be done
- // Return threadError if you want to be stop without a threadKill message
- // Return threadPause to pause your thread until ThreadResume() is called for it
- // Return threadDone if there's nothing left to do
-
- typedef ThreadResult (ThreadProc) (ThreadMessage command, void* threadData, long dataSize);
- // This is a type definition for your thread procedure, make something like:
- // ThreadResult MyThread(ThreadCommand command, void* threadData, long dataSize);
- // Command is what to do, (threadData, dataSize) are the data input for your thread
-
- typedef struct Thread Thread;
-
- Thread* ThreadAdd(Error* error, ThreadProc threadProc, void* threadData, long dataSize);
- // Create a new thread, returns thread or 0 if fail. Data copied into thread
- void ThreadKill(Thread* thread);
- // Kill the thread immediately (sends threadKill then disposes)
- void ThreadPause(Thread* thread);
- // Pauses the thread immediately
- void ThreadResume(Thread* thread);
- // Resumes the thread immediately
- Boolean ThreadsBusy();
- // Returns true if we have thread work to do, i.e. want to hog the CPU
- void ThreadsWork(long workTicks);
- // Sets threads to work for workTicks 60ths of a second - since this is
- // non-preemptive, it relies on the good will of threadProc!
-
- /*
- Essential Navigation.c
-
- These functions implement open and save file dialog boxes which automatically
- use Navigation Services if available (beginning Mac OS 8.5). To use these functions,
- you need to do 3 further things :
-
- 1. Add the NavigationLib library to your project (in :Libraries:MacOS Common). In
- order to work with pre-8.5 systems, make sure you select the 'Import Weak' option.
- 2. Create a 'kind' resource with kind strings for formats you can open
- (see Inside Macintosh: More Macintosh Toolbox). This is easiest with Rez.
- 3. Ensure that your drag-and-drop tracking and receiving code can cope with the fact
- that it may get messages for Navigation Services windows (silly if you ask me).
- */
-
- typedef struct {
- FSSpec fileSpec; // the full file
- Boolean folder, visible; // Boolean flags if a folder, if visible
- unsigned long created, modified; // Mac OS date/time structures
-
- union {
- struct {
- Boolean locked; // Boolean flag if file is locked
- Boolean dataOpen, resOpen; // Boolean flags if data or resource fork open
- unsigned long dataSize, resourceSize; // The logical size of these forks
- FInfo finderInfo; // Finder info structure (contains type, creator)
- FXInfo moreFinderInfo; // Additional Finder info
- }
- file; // Access this structure with .more.file
- struct {
- unsigned long numberFiles; // Number of files in folder
- DInfo finderInfo; // Finder info structure
- DXInfo moreFinderInfo; // Additional Finder info
- }
- folder; // Access this structure with .more.folder
- }
- more;
- } MADENavigationItemInfo;
- // This structure is passed to your filter procedure to give it the necessary
- // information about the file it is filtering
-
- typedef Boolean (MADENavigationItemFilter) (MADENavigationItemInfo* item);
- // This is a type definition for your navigation item filtering procedure
- // You want something like: Boolean MyFilter(MADENavigationItemInfo* item);
- // You should return true from this to _display_ the item (unlike StandardFile API)
-
- Boolean MADENavigationGetFile(OSType appCreator, short numberTypes, OSType types[],
- MADENavigationItemFilter* filter, FSSpec* resultFile, Boolean *stationery);
- // Does a get file (i.e. open dialog box) with or without Navigation Services
- // appCreator is your application's signature, numTypes is the number of types in types
- // (maximum is 4), -1 to pass all and use filter,
- // filter is an additional filtering procedure for items (0 for none),
- // resultFile will have the file to open, *stationery will be true if the file to open
- // is stationery (pass 0 if you don'y care). Returns true if user indicated to go ahead
-
- Boolean MADENavigationChooseFile(OSType appCreator, short numberTypes, OSType types[],
- MADENavigationItemFilter* filter, FSSpec* resultFile, Boolean *stationery);
- // Save as MADENavigationGetFile but uses Navigation Services' Choose interface
- // instead of Open interface. Also doesn't go through translation.
-
- Boolean MADENavigationChooseFolder(OSType appCreator, MADENavigationItemFilter* filter,
- FSSpec* resultFile);
- // Save as MADENavigationChooseFile but allows selection of a folder, either using
- // a customised Standard File dialog or Navigation Services.
-
- Boolean MADENavigationChooseFileOrFolder(OSType appCreator, MADENavigationItemFilter* filter,
- FSSpec* resultFile, Boolean *stationery);
- // Save as MADENavigationChooseFolder but allows selection of files _or_ a folder,
- // either using a customised Standard File dialog or Navigation Services.
-
- Boolean MADENavigationPutFile(Str255 prompt, OSType appCreator, OSType type,
- Str255 defaultName, FSSpec* resultFile, Boolean* replacing);
- // Does a put file (i.e. save as dialog box) with or without Navigation Services
- // prompt is the text prompt (0 for none), appCreator is your application's signature,
- // type is the type of file you will save, resultFile will have the file to save as,
- // defaultName is the default file name (0 for default), *replacing will be true if the
- // user is replacing a previous file. Returns true if user indicated to go ahead
-